{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item" >

                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px;">
                            <select name="coupon_status" lay-search="">
                                <option  value="">不限状态</option>
                                <option  value="1">上架中</option>
                                <option  value="2">已下架</option>
                            </select>
                        </div>

                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px;">
                            <input type="text" id="keyword" class="layui-input search" name="keyword" placeholder="优惠券名称/ID"/>
                        </div>

                        <div class="layui-input-inline" style="margin-top: 5px;">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('couponAdd')}');">
                            <i class="fa fa-plus"></i> 添加优惠券
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>

                    <!--图片模板-->


                    <!--状态显示模板-->
                    <script type="text/html" id="statBar">
                        {{# if(d.coupon_status == 1){ }}
                        上架中
                        {{# } }}
                        {{# if(d.coupon_status == 2){ }}
                        已下架
                        {{# } }}
                    </script>

                    <script type="text/html" id="numBar">
                        {{# if(d.coupon_total_num == 0){ }}
                        不限制
                        {{# }else{ }}
                        {{d.coupon_total_num}}
                        {{# } }}
                    </script>

                    <script type="text/html" id="typeBar">
                        {{# if(d.coupon_type == 1){ }}
                        满{{d.coupon_use_price}}减{{d.coupon_dikou_price}}
                        {{# } }}
                        {{# if(d.coupon_type == 2){ }}
                        无门槛
                        {{# } }}
                    </script>

                    <script type="text/html" id="sendBar">
                        {{# if(d.coupon_is_send == 1){ }}
                        未发送
                        {{# } }}
                        {{# if(d.coupon_is_send == 2){ }}
                        已发送
                        {{# } }}
                    </script>

                    <script type="text/html" id="rangeBar">
                        {{# if(d.coupon_range == 1){ }}
                        部分用户
                        {{# } }}
                        {{# if(d.coupon_range == 2){ }}
                        全部用户
                        {{# } }}
                    </script>

                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.layer_show('领取详情','{:url('getList')}?coupon_id={{d.coupon_id}}')" class="btn btn-warning btn-xs m-r-xs" title="领取详情"><i class="fa fa-search">领取详情</i></a>
                        <a href="javascript:;" onclick="wk.href('{:url('couponEdit')}?coupon_id={{d.coupon_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑"><i class="fa fa-pencil">编辑</i></a>
                        {{# if(d.coupon_status == 2) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.coupon_id}}','{:url('couponUp')}', '确定上架？')" class="btn btn-info btn-xs m-r-xs" title="上架"><i class="fa fa-arrow-up">上架</i></a>
                        {{# } }}
                        {{# if(d.coupon_status == 1) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.coupon_id}}','{:url('couponDown')}', '确定下架？')" class="btn btn-warning btn-xs m-r-xs" title="下架"><i class="fa fa-arrow-down">下架</i></a>
                        {{# } }}<a href="javascript:;" onclick="wk.confirm('{{d.coupon_id}}','{:url('couponDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Coupon/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
//                  {type: 'checkbox', fixed: 'left'}
//                , {type:'numbers', width: 60, title: '序号'}
                  {field: 'coupon_id', width: 60, title: 'ID', align: 'center'}
                , {field: 'coupon_status', width: 80, title: '状态', align: 'center', toolbar: '#statBar'}
                , {field: 'coupon_name', width: 150, title: '优惠券名称', align: 'center'}
                , {field: 'coupon_dikou_price', width: 90, title: '面值', align: 'center'}
                , {field: 'coupon_use_end_time', width: 110, title: '有效期', align: 'center'}
                , {field: 'coupon_total_num', width: 90, title: '发放数量', align: 'center', toolbar: '#numBar'}
                , {field: 'coupon_lingqu_num', width: 90, title: '领取数量', align: 'center'}
                , {field: 'use_num', width: 90, title: '使用数量', align: 'center'}
                , {field: 'lose_num', width: 90, title: '过期数量', align: 'center'}
                , {field: 'coupon_type', width: 140, title: '使用条件', align: 'center', toolbar: '#typeBar'}
                , {field: 'coupon_send_time', width: 150, title: '发送时间', align: 'center'}
                , {field: 'coupon_is_send', width: 90, title: '发送状态', align: 'center', toolbar: '#sendBar'}
                , {field: 'coupon_range', width: 100, title: '发送范围', align: 'center', toolbar: '#rangeBar'}
                , {fixed: 'right', width: 280, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });

        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['coupon_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>